package com.cl.short_video_java.config;


import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.aspect.IsRoleAspect;
import com.cl.short_video_java.aspect.LoginAspect;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author 付
 * @Date 2024-03-14 20:33
 * @Version 1.0
 * @description
 * @since 1.0
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	@Resource
	LoginAspect loginAspect;
	@Resource
	IsRoleAspect isRoleAspect;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(loginAspect)
				.addPathPatterns("/user/**")
				.addPathPatterns("/admin/**")
				.addPathPatterns("/role/**")
				.addPathPatterns("/order/**")
				.addPathPatterns("/shop/**")
				.addPathPatterns("/login_infor/**")
				.addPathPatterns("/maillog/**")
				.addPathPatterns("/operlog/**")
				.addPathPatterns("/mail/**")
				.addPathPatterns("/notice/**")
				.addPathPatterns("/setting/**")
				.addPathPatterns("/common/**")
				.excludePathPatterns("/admin/login", "/pay/**")
				.excludePathPatterns("/files/**");

		registry.addInterceptor(isRoleAspect)
				.addPathPatterns("/**")
				.excludePathPatterns("/admin/login", "/pay/**")
				.excludePathPatterns("/files/**");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/image/**").addResourceLocations("file:///E:/image/");
		registry.addResourceHandler("/img/**").addResourceLocations("file:E://项目//A//img//");
		registry.addResourceHandler("/video/**").addResourceLocations("file:E://项目//A//img//");
	}
}
